home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: Q: pointers to pointers that point to structs?
- Date: 11 Feb 1996 17:45:33 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4flrid$85i@umbc10.umbc.edu>
- References: <311C1B4E.217F@mars.superlink.net>
- NNTP-Posting-Host: umbc10.umbc.edu
- NNTP-Posting-User: schlein
-
- Michael Rizzo <rizzom@mars.superlink.net> wrote:
- |> I am having trouble dereferencing a pointer to a pointer to a struct.
- |> For simplicity just say the struct is:
- |> struct test
- |> {
- |> char teststr[10];
- |> int testint;
- |> }
-
- You may want a ; after the struct definition.
-
- |> Now I have a function that just wants to print elements of the
- |> structure:
- |>
- |> void f(test **temp)
-
- You mean:
-
- void f (struct test **temp)
-
- |> {
- |> printf("%s %d",(please fill in the blank))
-
- Well assuming dereferencing the pointers at both levels are legal then
- just do:
-
- printf ("%s %d", (**temp).teststr, (**temp).testint);
-
- Also don't forget to #include <stdio.h> for the printf() calls...
-
- |> }
- |>
- |> How to I get to test.teststr and test.testint from within the funtion.
- |> I have tried temp->teststr. I'm still pretty new to programming in C,
- |> and the book I'm using does not go into such topics, so any help would
- |> be greatly appreciated.
-
- Well temp->teststr would be correct if you only had one level of pointers.
- So an alternate way would be:
-
- printf ("%s %d", (*temp)->teststr, (*temp)->testint);
-
- This is not necessarily the only 2 ways although both will do what you
- have asked.
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-